package com.lineage.data.item_etcitem.add;

import com.lineage.config.Configtype;
import com.lineage.data.cmd.EnchantWeapon;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import java.util.Random;

public class Ran_EnchantArmor extends ItemExecutor {
  private int _chance;
  
  public static ItemExecutor get() {
    return new Ran_EnchantArmor();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    if (tgItem.getItem().getType2() != 2) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("物品必须是防具系列"));
      return;
    } 
    if (tgItem.getItem().get_safeenchant() < 0 || tgItem.getBless() >= 128) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    int use_type = tgItem.getItem().getUseType();
    if (use_type == 23 || use_type == 24 || use_type == 37 || use_type == 40) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("饰品无法使用。"));
      return;
    } 
    if (tgItem.getEnchantLevel() >= Configtype.armorlv) {
      pc.sendPackets((ServerBasePacket)new S_SystemMessage("已经超过最高强化上限。"));
      return;
    } 
    pc.getInventory().removeItem(item, 1L);
    Random random = new Random();
    EnchantWeapon enchantWeapon = new EnchantWeapon();
    if (this._chance > random.nextInt(100) + 1) {
      enchantWeapon.successEnchant(pc, tgItem, 1);
    } else {
      enchantWeapon.successEnchant(pc, tgItem, 0);
    } 
  }
  
  public void set_set(String[] set) {
    try {
      this._chance = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
  }
}
